package de.schweigerconsulting.util.csv;

/**
 * Copyright 2011 Stefan Schweiger
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License. 
 * 
 * The CsvHeadline class provides the data (column names) of the
 * current CSV file and all required methods to work with it.
 * 
 * @author Stefan Schweiger
 * @version 0.1.0 (Date: 12/15/2009)
 * 
 */
public class CsvHeadline {
	/**
	 * The <code>char</code> array <code>data</code> contains the column names.
	 */
	String[] data;

	/**
	 * Class constructor to create an instance.
	 */
	protected CsvHeadline() {
		super();
	}

	/**
	 * Class constructor specifying <code>data</code> (column names).
	 * 
	 * @param data
	 *            A <code>char</code> array containing all column names.
	 */
	protected CsvHeadline(String[] data) {
		super();
		this.data = data;
	}

	/**
	 * Returns the <code>data</code> (char array) attribute.
	 * 
	 * @return A <code>char</code> array containing all column names.
	 */
	protected String[] getData() {
		return this.data;
	}

	/**
	 * Sets the <code>data</code> attribute.
	 * 
	 * @param data
	 *            A <code>char</code> array containing all column names.
	 */
	protected void setData(String[] data) {
		this.data = data;
	}

	/**
	 * Returns the index of the given column name.
	 * 
	 * @param columnName
	 *            The column name, whose index is to be determined.
	 * @return The index of the given column name. -1 if the column name was not
	 *         found.
	 */
	protected int getColumnIndex(String columnName) {
		int result = 0;

		for (String column : data) {
			if (column.equals(columnName)) {
				return result;
			}
			result++;
		}

		return -1;
	}
}
